
import java.util.*;

public class TimeNotifier extends Timer {

   public static final int MINS_TO_MILLIS = 60000;

   private int waitMins = 0;
   private TimerCallback callback = null;

   public TimeNotifier( TimerCallback callback ) {
      super( "TimeNotifier", false ); //daemon thread
      this.callback = callback;
   }

   public void schedule( int waitMins ) {
      this.waitMins = waitMins;
      this.scheduleAtFixedRate( new ProgressTask( callback ), new Date(), MINS_TO_MILLIS );
      this.schedule( new CallbackTask( callback ), waitMins*MINS_TO_MILLIS );
   }

   class CallbackTask extends TimerTask {
      private TimerCallback callback = null;
      public CallbackTask( TimerCallback callback ) {
         super();
         this.callback = callback;
      }
      public void run() {
         callback.timer();
      }
   }
   
   class ProgressTask extends TimerTask {
      private TimerCallback callback = null;
      public ProgressTask( TimerCallback callback ) {
         super();
         this.callback = callback;
      }
      public void run() {
         callback.progress();
      }
   }

}
